'''
Created on Oct 11, 2009

@author: jaimeblasco
'''
from fastflux.monitor.models import *
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import Context, loader
import datetime

def index(request):
    t = loader.get_template('monitor/base.html')
    c = Context({})
    return HttpResponse(t.render(c))

def domains(request):
    t = loader.get_template('monitor/domains.html')
    try:
        domains = Domain.objects.all()
    except:
        msg = "Domain does not exist"
        return render_to_response('monitor/error.html', {'msg': msg})
    
    c = Context({'domains':domains})
    return HttpResponse(t.render(c))

def domain(request, domain):
    t = loader.get_template('monitor/domain.html')
    nodes = Node.objects.filter(domain__name=domain)
    c = Context({'nodes':nodes,'domain':domain})    
    return HttpResponse(t.render(c))
    

